/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.jiadakeji.ppm.modules.business.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.jiadakeji.ppm.common.config.Global;
import com.jiadakeji.ppm.common.persistence.Page;
import com.jiadakeji.ppm.common.web.BaseController;
import com.jiadakeji.ppm.common.utils.StringUtils;
import com.jiadakeji.ppm.modules.sys.utils.UserUtils;
import com.jiadakeji.ppm.modules.business.entity.RoomTypePrice;
import com.jiadakeji.ppm.modules.business.service.RoomTypePriceService;

/**
 * 房屋类型价格Controller
 * @author HHAOYU
 * @version 2019-07-09
 */
@Controller
@RequestMapping(value = "${adminPath}/business/roomTypePrice")
public class RoomTypePriceController extends BaseController {

	@Autowired
	private RoomTypePriceService roomTypePriceService;
	
	@ModelAttribute
	public RoomTypePrice get(@RequestParam(required=false) String id) {
		RoomTypePrice entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = roomTypePriceService.get(id);
		}
		if (entity == null){
			entity = new RoomTypePrice();
		}
		return entity;
	}
	
	@RequiresPermissions("business:roomTypePrice:view")
	@RequestMapping(value = {"list", ""})
	public String list(RoomTypePrice roomTypePrice, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<RoomTypePrice> page = roomTypePriceService.findPage(new Page<RoomTypePrice>(request, response), roomTypePrice); 
		model.addAttribute("page", page);
		
		UserUtils.putCache("roomTypePrice", roomTypePrice);
		return "modules/business/roomTypePriceList";
	}

	@RequiresPermissions("business:roomTypePrice:view")
	@RequestMapping(value = "form")
	public String form(RoomTypePrice roomTypePrice, Model model) {
		model.addAttribute("roomTypePrice", roomTypePrice);
		return "modules/business/roomTypePriceForm";
	}

	@RequiresPermissions("business:roomTypePrice:edit")
	@RequestMapping(value = "save")
	public String save(RoomTypePrice roomTypePrice, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, roomTypePrice)){
			return form(roomTypePrice, model);
		}
		roomTypePriceService.save(roomTypePrice);
		addMessage(redirectAttributes, "保存房屋类型价格成功");
		
		redirectAttributes.addFlashAttribute("roomTypePrice", UserUtils.getCache("roomTypePrice"));
		return "redirect:"+Global.getAdminPath()+"/business/roomTypePrice/?repage";
	}
	
	@RequiresPermissions("business:roomTypePrice:edit")
	@RequestMapping(value = "delete")
	public String delete(RoomTypePrice roomTypePrice, RedirectAttributes redirectAttributes) {
		roomTypePriceService.delete(roomTypePrice);
		addMessage(redirectAttributes, "删除房屋类型价格成功");
		
		redirectAttributes.addFlashAttribute("roomTypePrice", UserUtils.getCache("roomTypePrice"));
		return "redirect:"+Global.getAdminPath()+"/business/roomTypePrice/?repage";
	}

}